package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.Serviceprovider.BanlanceDetActivity;
import com.laiyima.zhongjiang.linghuilv.demo.bean.BalanceBean;
import com.laiyima.zhongjiang.linghuilv.demo.view.MyListView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class BalanceAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<BalanceBean> balanceBean;
    List<BalanceChildAdapter> pAdapterList = new ArrayList<BalanceChildAdapter>();
    public BalanceAdapter(BanlanceDetActivity context, List<BalanceBean> list) {
        this.mInflater = LayoutInflater.from(context);
        this.balanceBean = list;
        this.mContext = context;
        for (int i = 0; i < list.size(); i++) {
            BalanceChildAdapter pAdapter = new BalanceChildAdapter(context, list.get(i).getItems(),
                    this);
            pAdapterList.add(pAdapter);
        }
    }

    @Override
    public int getCount() {
        return balanceBean.size();
    }

    @Override
    public Object getItem(int position) {
        return balanceBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.banlance_item,null);
            viewHolder = new ViewHolder();
            viewHolder.time = convertView.findViewById(R.id.balance_time_key);
            viewHolder.day_money = convertView.findViewById(R.id.balance_month_money);
            viewHolder.listView = (MyListView)convertView.findViewById(R.id.balance_childer_list);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        BalanceBean ewTranBean = balanceBean.get(position);
        if(ewTranBean.getItems()==null){}

        String time=ewTranBean.getKey();
        String nian=time.substring(0,4);
        String yue=time.substring(5,7);
        viewHolder.time.setText(nian+"年"+yue+"月");

        Double a1 = Double.parseDouble(ewTranBean.getMoney());
        DecimalFormat decimalFormatq = new DecimalFormat("0.00");
        String b1 = decimalFormatq.format(a1);

        viewHolder.day_money.setText("提现  "+b1+"元");
        viewHolder.listView.setAdapter(pAdapterList.get(position));
        return convertView;
    }

    public static class ViewHolder{
        TextView time;
        TextView day_money;
        MyListView listView;
    }
}
